﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using QLHD.BLL;

namespace QLHD.DAL
{
    public class MaTP_DB
    {
        public static DataTable SelectMaTP_PhanLoai()
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("select * from tblChiTietMaTP where MaQt like 'qt5'", con);
                con.Open();
                SqlCommand command = new SqlCommand("select * from tblChiTietMaTP where MaQt like 'qt5'", con);
                command.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        public static DataTable SelectMaTP_BocLua()
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("select * from tblChiTietMaTP where MaQt like 'qt4'", con);
                con.Open();
                SqlCommand command = new SqlCommand("select * from tblChiTietMaTP where MaQt like 'qt4'", con);
                command.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        public static DataTable SelectMaTP_Say()
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("select * from tblChiTietMaTP where MaQt like 'qt3'", con);
                con.Open();
                SqlCommand command = new SqlCommand("select * from tblChiTietMaTP where MaQt like 'qt3'", con);
                command.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        public static DataTable SelectMaTP()
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("select * from tblChiTietMaTP", con);
                con.Open();
                SqlCommand command = new SqlCommand("select * from tblChiTietMaTP", con);
                command.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        public static DataTable SelectMaTP_THTN()
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("select * from tblChiTietMaTP where MaQt like 'qt2'", con);
                con.Open();
                SqlCommand cmd = new SqlCommand("select * from tblChiTietMaTP where MaQt like 'qt2'", con);
                cmd.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }

        }

        public static void Insert(MaTP matp)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spThemMaTP", con);
                con.Open();
                SqlCommand command = new SqlCommand("spThemMaTP", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaTP", matp.Matp);
                command.Parameters.AddWithValue("@DienGiai", matp.Diengiai);
                command.ExecuteNonQuery();

            }
        }
        public static void Update(string oldMatp, MaTP matp)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spCapNhatMaTP", con);
                con.Open();
                SqlCommand command = new SqlCommand("spCapNhatMaTP", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaTP", oldMatp);
                command.Parameters.AddWithValue("@DienGiai", matp.Diengiai);
                command.ExecuteNonQuery();

            }
        }
        public static void Delete(string matp)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spXoaMaTP", con);
                con.Open();
                SqlCommand command = new SqlCommand("spXoaMaTP", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaTP", matp);
                command.ExecuteNonQuery();

            }
        }
    }
}
